package com.lijiaxing.mapper;

import com.lijiaxing.pojo.PermissionRes;
import com.lijiaxing.pojo.UserRes;
import com.lijiaxing.pojo.verificationCode;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;


@Mapper
public interface userMapper {
    //查询验证码
    @Select("SELECT * FROM verification_code WHERE tel='${utel}' AND vcode='${ucode}' ")
    verificationCode[] queryVerification(String utel, String ucode);

    //根据utel查询一个用户存在
    @Select("SELECT * FROM users WHERE utel='${utel}'")
    UserRes.User[] queryOneUserByUtel(String utel);

    //根据utel和uid查询一个用户存在
    @Select("SELECT * FROM users WHERE utel='${utel}' AND uid!='${uid}'")
    UserRes.User[] queryOneUserByUtelAndUid(String utel, String uid);

    //注册
    @Insert("INSERT INTO users(utel,upwd,create_time) VALUES ('${utel}','${upwd}',now())")
    int setOneRegister(String utel, String upwd);

    //登录
    @Select("SELECT * FROM users WHERE utel='${utel}'AND upwd='${upwd}'")
    UserRes.User[] queryOneUserByArgs(String utel, String upwd);

    //添加一个权限
    @Insert("INSERT INTO permissionData(pname,permissions,permissionsName) VALUES ('${pname}','${permissions}','${permissionsName}')")
    int addPermission(String pname, String permissions, String permissionsName);

    //通过名字查询一个权限
    @Select("SELECT * FROM permissionData WHERE pname='${pname}'")
    PermissionRes.Permission[] queryOnePermission(String pname);

    //通过名字和id查询一个权限
    @Select("SELECT * FROM permissionData WHERE pname='${pname}'AND pid!='${pid}'")
    PermissionRes.Permission[] queryOnePermissionByNameAndId(Integer pid, String pname);

    //查询所有一页权限
    @Select("SELECT * FROM permissionData LIMIT ${pageNum},${pageSize};")
    PermissionRes.Permission[] queryOnePagePermission(int pageNum, int pageSize);

    //查询所有权限
    @Select("SELECT pid,pname FROM permissionData;")
    PermissionRes.Permission[] queryAllPermissions();

    //查询所有权限数量
    @Select("SELECT COUNT(*) FROM permissionData;")
    int queryAllPermissionCount();

    @Update("UPDATE permissionData SET pname='${pname}',permissions='${permissions}',permissionsName='${permissionsName}' WHERE pid=${pid}")
    int updatePermission(Integer pid, String pname, String permissions, String permissionsName);
}
